package com.lyloou.practice.utils;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Component;

/**
 * @author lyloou
 * @date 2020/06/02
 * @desc
 */
@Component
@Aspect
@EnableAspectJAutoProxy
public class LogUtils {

    @Pointcut("execution(public void com.lyloou.practice.service.impl.TransferServiceImpl.transfer(java.lang.String,java.lang.String,int))")
    public void pt() {
    }


    @Before("pt()")
    public void before(JoinPoint joinPoint) throws Throwable {
        System.out.println("LogUtils.before");
    }

    @After("pt()")
    public void after(JoinPoint joinPoint) throws Throwable {
        System.out.println("LogUtils.after");
    }

    @AfterThrowing("pt()")
    public void afterThrowing(JoinPoint joinPoint) throws Throwable {
        System.out.println("LogUtils.afterThrowing");
    }

    @Around("pt()")
    public Object around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        System.out.println("LogUtils.around before");
        Object result = proceedingJoinPoint.proceed(proceedingJoinPoint.getArgs());
        System.out.println("LogUtils.around after");
        return result;
    }


    @AfterReturning(value = "pt()", returning = "result")
    public void afterReturning(JoinPoint joinPoint, Object result) throws Throwable {
        System.out.println("LogUtils.afterReturning");
        System.out.println(result);
    }
}
